
$(function(){
    $('#update').on('click', function() {
    	var dataJson=getFormDatatoJson("paper");
    	var flag=validate(dataJson);
    	if(flag){
    		$.ajax({
        		url: '/examReport/updateExaminationOnTheSpot',
        		type: 'post',
        		async:false,
        		cache:false,
        		data: dataJson,
        		success: function () {
        			$.Zebra_Dialog('<div class="prompt"><div class="success-icon"></div><div class="success-title">修改成功!</div></div>', {
		                'title': '提示',
		                'buttons' : [ {
							caption : '确定',
							callback : function() {
								window.location.href="/examReport/examinationOnTheSpot";
							}
						} ]
		            });
        		}
        	});
    	}
    	
    });  
});
function validate(dataJson){
	 var totalScore=parseFloat($("#totalScore").val());
	 var score=parseFloat(dataJson["score"]);
	 console.log(score);
	 if(score>totalScore){
		 zebra_Dialog_warning("输入分值不能大于试卷总分!");
		 return false;
	 }else if(!(/^\d+(\.\d+)?$/.test(score))&&!(/(^[0-9]\d*$)/.test(score))){
		 zebra_Dialog_warning("输入分值不能为空!");
		 return false;
	 }
	 return true;
}
function getFormDatatoJson(id) {
    var dataJson = {};
    $("#"+id).serializeArray().map(function (x) {
        if (dataJson[x.name ] !== undefined) {
            if (!dataJson[x.name].push) {
                dataJson[x.name] = [dataJson[x.name]];
            }
            dataJson[x.name].push(x.value || '');
        } else {
            dataJson[x.name] = x.value || '';
        }
    });
    return dataJson;
}
